package aod.android.com.bernay.view.activity;

import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import aod.android.com.bernay.R;
import aod.android.com.bernay.base.BernayBaseActivity;
import aod.android.com.bernay.http.BernayApi;
import aod.android.com.bernay.http.BernayCallback;
import aod.android.com.bernay.live.adapter.InfoAdapter;
import aod.android.com.bernay.live.bean.HomeListBean;
import aod.android.com.bernay.live.bean.LiveHFBean;
import aod.android.com.bernay.util.SharePreUtils;
import chen.lion.hilib.util.LogUtils;
import chen.lion.hilib.view.bind.HiView;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;

public class VideoInfoActivity extends BernayBaseActivity {

    @HiView(R.id.live_video_vv)
    public JCVideoPlayer mVideo;

    private List<LiveHFBean> mDatas = new ArrayList<>();


    private InfoAdapter mAdapter;

    @HiView(R.id.scro_view)
    private ScrollView mScrollView;


    @HiView(R.id.data_list)
    private ListView mListView;

    @HiView(R.id.send)
    private EditText mSendEdit;

//    @HiView(R.id.title_video)
//    private TextView mTitleTv;


    @HiView(R.id.live_user_name_tv)
    private TextView mUserNameTv;


    @HiView(R.id.content)
    private TextView mContentTv;

    private HomeListBean.DataBean dataBean =  new HomeListBean.DataBean();
    private SimpleDateFormat mFormat = new SimpleDateFormat("MM.dd HH:mm");

    private boolean isHF = false;
    @Override
    protected int initLayout() {
        return R.layout.activity_video_info;
    }

    @Override
    protected void initData() {
        if(getIntent().getSerializableExtra("liveBean")!=null){
            dataBean = (HomeListBean.DataBean) getIntent().getSerializableExtra("liveBean");
        }
        initTitle(dataBean.getTitle(), R.drawable.icon_fixing_share, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showError("分享施工中");
            }
        });

//        mTitleTv.setText(dataBean.getTitle());
        mUserNameTv.setText(dataBean.getNickName());
        mContentTv.setText(dataBean.getDetail());
        setStatusBarFontDark(false);
        mVideo.setUp(dataBean.getSource(), "", dataBean.getTitle());
        initDatas();
        mAdapter = new InfoAdapter(mDatas,this);
        mListView.setAdapter(mAdapter);
        mScrollView.smoothScrollTo(0,0);
        mSendEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(final TextView v, int actionId, KeyEvent event) {

                if (actionId == EditorInfo.IME_ACTION_SEND) {
                   // showLoding();
                    BernayApi.http().postVideoText(SharePreUtils.newInstance(mContext).getUserId(),
                            SharePreUtils.newInstance(mContext).getUserId(),
                            dataBean.getId(), v.getText().toString(), new BernayCallback() {
                                @Override
                                public void onJsonData(String json) {
                                    LiveHFBean bean1 = new LiveHFBean();
                                    bean1.setUserName("测试发送账号");
                                    bean1.setUserUrl("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3703406506,2565705466&fm=27&gp=0.jpg");
                                    bean1.setDate(mFormat.format(new Date()));
                                    bean1.setLove(10);
                                    bean1.setuId(12);
                                    bean1.setContent(v.getText().toString());
                                    mDatas.add(bean1);
                                    mAdapter.notifyDataSetChanged();
                                   // showSuccess();
                                    mSendEdit.setText("");
                                }

                                @Override
                                public void onHttpFailure(IOException e) {

                                }
                            });

                }
                return false;
            }
        });
    }

    public void initDatas(){
        BernayApi.http().getVideoInfo(SharePreUtils.newInstance(VideoInfoActivity.this).getUserId(),
                SharePreUtils.newInstance(VideoInfoActivity.this).getToken(), dataBean.getId(), new BernayCallback() {
                    @Override
                    public void onJsonData(String json) {
                        LogUtils.e(json);
                    }
                    @Override
                    public void onHttpFailure(IOException e) {

                    }
                });

        BernayApi.http().getCommentlist(SharePreUtils.newInstance(this).getUserId(), SharePreUtils.newInstance(VideoInfoActivity.this).getToken(),
                "1", "10", dataBean.getId(), new BernayCallback() {
                    @Override
                    public void onJsonData(String json) {

                    }

                    @Override
                    public void onHttpFailure(IOException e) {

                    }
                });

        LiveHFBean bean1 = new LiveHFBean();
        bean1.setUserName("我爱可可西里");
        bean1.setUserUrl("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2947370426,1430221852&fm=27&gp=0.jpg");
        bean1.setDate("04.10 10:45");
        bean1.setLove(10);
        bean1.setuId(12);
        bean1.setContent("取消塑料品，多用竹器，无污染！");

        LiveHFBean bean2 = new LiveHFBean();
        bean2.setUserName("混世魔王");
        bean2.setUserUrl("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2011199424,1031715062&fm=27&gp=0.jpg");
        bean2.setDate("04.10 10:47");
        bean2.setLove(40);
        bean2.setuId(13);
        bean2.setContent("有点意思！");
        
        LiveHFBean bean3 = new LiveHFBean();
        bean3.setUserName("李小美");
        bean3.setUserUrl("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1479419211,3323294303&fm=27&gp=0.jpg");
        bean3.setDate("04.10 10:49");
        bean3.setLove(20);
        bean3.setuId(14);
        bean3.setContent("什么有点意思？");
        bean3.setoContent("有点意思！");
        bean3.setoId(13);
        bean3.setoName("混世魔王");


        LiveHFBean bean4 = new LiveHFBean();
        bean4.setUserName("混世魔王");
        bean4.setUserUrl("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2011199424,1031715062&fm=27&gp=0.jpg");
        bean4.setDate("04.10 10:59");
        bean4.setLove(20);
        bean4.setuId(14);
        bean4.setContent("你就这么想知道么？");
        bean4.setoContent("什么有点意思！");
        bean4.setoId(13);
        bean4.setoName("李小美");
        mDatas.add(bean1);
        mDatas.add(bean2);
        mDatas.add(bean3);
        mDatas.add(bean4);


    }
}
